maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=mesonlsp
pkgver=4.3.7
pkgrel=0
_sha2_commit=b29613850d6e54e7159197ef42c7d22d012b6367
_muon_commit=a9bd9889cf0c4849da1c6150c8d6558817655364
_tree_sitter_ini_commit=848b6269f7039739aebd169fbd3d5e6e34bef661
_tree_sitter_meson_commit=09665faff74548820c10d77dd8738cd76d488572
pkgdesc="Language server for Meson"
url="https://github.com/JCWasmx86/mesonlsp"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	meson
	cmake
	ada-dev
	curl-dev
	gtest-dev
	libarchive-dev
	pkgconf-dev
	tomlplusplus-dev
	util-linux-dev
	tree-sitter-dev
	nlohmann-json
	"
checkdepends="
	git
	mercurial
	subversion
	py3-lsprotocol
	py3-gls
	"
# sha-2 dependency is temporary (ref: https://github.com/JCWasmx86/mesonlsp/issues/28#issuecomment-1875710406)
# muon, tree-sitter-ini and tree-sitter-meson include patches from the author that aren't upstreamed
source="
	$pkgname-$pkgver.tar.gz::https://github.com/JCWasmx86/mesonlsp/archive/refs/tags/v$pkgver.tar.gz
	sha-2-$_sha2_commit.tar.gz::https://github.com/amosnier/sha-2/archive/$_sha2_commit.tar.gz
	muon-$_muon_commit.tar.gz::https://github.com/JCWasmx86/muon/archive/$_muon_commit.tar.gz
	tree-sitter-ini-$_tree_sitter_ini_commit.tar.gz::https://github.com/JCWasmx86/tree-sitter-ini/archive/$_tree_sitter_ini_commit.tar.gz
	tree-sitter-meson-$_tree_sitter_meson_commit.tar.gz::https://github.com/JCWasmx86/tree-sitter-meson/archive/$_tree_sitter_meson_commit.tar.gz
	system-ada.patch
	"

prepare() {
	default_prepare

	mv "$srcdir"/sha-2-$_sha2_commit "$srcdir"/sha256
	mv "$srcdir"/muon-$_muon_commit "$srcdir"/muon
	mv "$srcdir"/tree-sitter-ini-$_tree_sitter_ini_commit "$srcdir"/tree-sitter-ini
	mv "$srcdir"/tree-sitter-meson-$_tree_sitter_meson_commit "$srcdir"/tree-sitter-meson
}

build() {
	export MESON_PACKAGE_CACHE_DIR="$srcdir"
	abuild-meson \
		-Db_lto=true \
		-Duse_own_tree_sitter=false \
		-Dbenchmarks=false \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# Remove the symlink referencing the old project name
	rm "$pkgdir"/usr/bin/Swift-MesonLSP
}

sha512sums="
06e598e66fd237170e15ef80cf1eaafbb48b30e9692bdc77038a473c1dac3772ded2083e6a4f0f142cd1118f1d9b2e7c5223186ab897b12a4b7aab3ef85c1873  mesonlsp-4.3.7.tar.gz
8bb69db683acb7381985c5120c1e43bc08ff044a127b3015882a21ce953e74a19ce4e25dc9cf9468a2aee941a5c4dfc461fe07e23c0e7d41b9863f433ec2e5c4  sha-2-b29613850d6e54e7159197ef42c7d22d012b6367.tar.gz
c756bd99a278196c1f2d94535999cab2fdd620024e6f7066238f47e7dd591ea040429538f2f577d1e82235e3ee6b1d1e77bfde4baf0eb0a361afa6eac9dd7cdc  muon-a9bd9889cf0c4849da1c6150c8d6558817655364.tar.gz
4cad6631fdcabf827f075db704422966e343e1aa351dc22d53f1cdde02988f82dc759c2563c5000ba7d8c5eec2a9961fa9159e20b9238cd6acba4213bd5226e8  tree-sitter-ini-848b6269f7039739aebd169fbd3d5e6e34bef661.tar.gz
a9f1d1ae7d6fea2f8f61ec073831f0771eec5bff3f420926cb65d3be0ef30f711f2c98c62b79ba9e5c82465f51e2887f6cd5ba096652933d2062d9532e0b223e  tree-sitter-meson-09665faff74548820c10d77dd8738cd76d488572.tar.gz
5c64eacef53febf01dd927af735f9a02bba328e4b0462cad94415462b9ce8a069ef410d91781ae0f25deed119fe9ae0eb56a6dc74c2ed4be61a12e7fd26e9aad  system-ada.patch
"
